module b_bcd(
	input	    [11:0]	bin_in,

	output  reg [3:0]   ones,
    output  reg [3:0]   tens,
    output  reg [3:0]   hundreds,
    output  reg [3:0]   thousand
);

integer i;

always @(*) begin
	ones 		= 4'd0;
	tens 		= 4'd0;
	hundreds 	= 4'd0;
    thousand 	= 4'd0;
	
	for(i = 11; i >= 0; i = i - 1) begin
		if (ones >= 4'd5) 		ones = ones + 4'd3;
		if (tens >= 4'd5) 		tens = tens + 4'd3;
		if (hundreds >= 4'd5)	hundreds = hundreds + 4'd3;
        if (thousand >= 4'd5)	thousand = thousand + 4'd3;

        thousand = {thousand[2:0]   ,hundreds[3]    };
		hundreds = {hundreds[2:0]   ,tens[3]        };
		tens	 = {tens[2:0]       ,ones[3]        };
		ones	 = {ones[2:0]       ,bin_in[i]      };
	end
end

endmodule